home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoRemoveLargeSlots.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.4 KB  |  274 lines

  1. /*
  2.  *   $RCSfile: undoRemoveLargeSlots.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoRemoveLargeSlots(
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     LGNODE                *lgNode;
  86.     SLOTTEDPAGE            *slottedPage;
  87.     PAGETYPE            pageType;
  88.     PAGE2SIZE           page2size;
  89.     PAGESLOT            *slotPtr;
  90.     SMALLOBJ            *objPtr;
  91.     LRC                 *pageLRC;
  92.     char                *oldData;
  93.     int                    oldDataSize;
  94.     PID                    *pid;
  95.     LGWRITEINFO         *lgWriteInfo;
  96.     LOGRECORDINFO       recordInfo;
  97. #ifdef INIT_LRC_IS_LSN
  98.     LRC                 tempLRC;
  99.     LRC                 *lrc = &tempLRC;
  100. #else
  101.     LRC                 *lrc;
  102. #endif /* INIT_LRC_IS_LSN; */
  103.     LSN                    lsn;
  104.     FORCEMARK            forceMark;
  105.     BOOL                actionDone;    /* Indicates whether the action
  106.                                        was ever performed on the page */
  107.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  108.  
  109.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  110.  
  111.  
  112.     /*
  113.      *    get a pointer to the page for the record
  114.      */
  115.     pid = &(recordHeader->actionPid);
  116.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  117.  
  118.     /*
  119.      *    get pointer to oid, header info
  120.      */
  121.     lgWriteInfo = (LGWRITEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  122.  
  123.     /*
  124.      *    get a pointer to the old data and its size in the record
  125.      */
  126.     oldData = GET_LOG_IMAGE(recordHeader, 1);
  127.     oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 1);
  128.     SM_ASSERT(LEVEL_3, oldDataSize == lgWriteInfo->size);
  129.  
  130.     /*
  131.      *    read in the page, first determine if it's a root on a 
  132.      *     slotted page
  133.      */
  134.    if (lgWriteInfo->rootSlot != NIL) {
  135.         pageType = PAGE_SLOTTED;
  136.         page2size = SLOTTED_PAGE2SIZE;
  137.     } else {
  138.         pageType = PAGE_LARGENODE;
  139.         page2size = LG_PAGE2SIZE;
  140.     }
  141.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
  142.  
  143.         SM_ERROR(TYPE_FATAL, Active->errno);
  144.     }
  145.     groupLink->pageHash->pageType = pageType;
  146.  
  147.     /*
  148.      *    get a pointer to the large node page
  149.      */
  150.     if (lgWriteInfo->rootSlot == NIL) {
  151.         lgNode = (LGNODE *) groupLink->bufFrame;
  152.         pageLRC = &(lgNode->header.lrc);
  153.         CHECK_LARGENODE_MAGIC(lgNode);
  154.     } else {
  155.         /*
  156.          *  Root node on slotted page
  157.          */
  158.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  159.         pageLRC = &(slottedPage->header.lrc);
  160.         SM_ASSERT(LEVEL_3, !CHECK_SLOTTED_MAGIC(slottedPage));
  161.     }
  162.  
  163.     /*
  164.      *    See if the action was actually done
  165.      */ 
  166.      actionDone = compareLRC(&(recordHeader->actionLRC), pageLRC) <= 0;
  167.     
  168.     /*
  169.      *    it is possible that the action 
  170.      *    never made it to the page on the server, so missing update
  171.      *    information may need to be recorded
  172.      *
  173.      *    Process any missing updates, and return a pointer to
  174.      *    the lrc to increment.  This will either be the lrc on the
  175.      *    slotted page, or the lrc in the missingUpdatePageTable
  176.      */
  177.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  178.                          pageLRC,
  179.                          groupLink->pageHash, recordHeader, pageType);
  180.  
  181.     /*
  182.      *    increment the lrc on the page
  183.      */
  184.     GENERATE_LRC(lrc);
  185.  
  186.     /*
  187.      *    Log the undo write
  188.      */
  189.     if (recordHeader->action == LOG_ACTION_REMOVE_LARGE_SLOTS) {
  190.         recordInfo.action       = LOG_ACTION_APPEND_LARGE_SLOTS;
  191.     } else {
  192.         SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_DELETE_LARGE_SLOTS);
  193.         recordInfo.action       = LOG_ACTION_INSERT_LARGE_SLOTS;
  194.     }
  195.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  196.     recordInfo.imageCount   = 2;
  197.     recordInfo.actionPid    = pid;
  198.     recordInfo.actionLRC    = lrc;
  199.     recordInfo.imageSize[0] = sizeof(LGWRITEINFO);
  200.     recordInfo.imageData[0] = (VOID *) lgWriteInfo;
  201.     recordInfo.imageSize[1] = (unsigned short) oldDataSize;
  202.     recordInfo.imageData[1] = (VOID *) oldData;
  203.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  204.     recordInfo.flags        = NOFLAGS;
  205.  
  206.     /*
  207.      *    write the record to the log
  208.      */
  209.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  210.                               &lsn, NOFLAGS)) < 0)  {
  211.         SM_ERROR(TYPE_FATAL, Active->errno);
  212.     }
  213.  
  214.     /*
  215.      *    mark the page dependency
  216.      */
  217. #ifndef INIT_LRC_IS_LSN
  218.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  219. #endif
  220.  
  221.     /*
  222.      *    perform the undo, if the action was performed
  223.      */
  224.     if (actionDone) {
  225.  
  226. #ifdef INIT_LRC_IS_LSN
  227.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  228. #endif
  229.  
  230.         /*
  231.          *    get a pointer to the large node page
  232.          */
  233.         if (lgWriteInfo->rootSlot != NIL) {
  234.             /*
  235.              *  Root node on slotted page
  236.              */
  237.             SM_ASSERT(LEVEL_3, lgWriteInfo->rootSlot < slottedPage->header.slotCount);
  238.             slotPtr = GETSLOTPTR(slottedPage, lgWriteInfo->rootSlot);
  239.             objPtr = GETOBJECTPTR(slottedPage, slotPtr);
  240.             lgNode = (LGNODE*) objPtr->data;
  241.             CHECK_SLOTROOT_MAGIC(lgNode);
  242.         }
  243.  
  244.         /*
  245.          *    If this is undoing a delete, shift up slots to make
  246.          *    room for the inserted data.
  247.          */
  248.         if (recordHeader->action == LOG_ACTION_DELETE_LARGE_SLOTS) {
  249.             bcopy(((char*)lgNode->slot) + lgWriteInfo->start,
  250.                   ((char*)lgNode->slot)+lgWriteInfo->start+lgWriteInfo->size,
  251.                   (int) (lgNode->header.numSlots*sizeof(LGSLOT)) - lgWriteInfo->start );
  252.  
  253.         }
  254.  
  255.         /*
  256.          *    Restore the old data
  257.          */
  258.         lgNode->header.numSlots += lgWriteInfo->size / sizeof(LGSLOT);
  259.         bcopy(oldData, ((char*)lgNode->slot) + lgWriteInfo->start, (int) oldDataSize);
  260.     }
  261.  
  262.     /*
  263.      *    signal the semaphore and unfix the page, dirty the page if
  264.      *    the action was done
  265.      */
  266.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  267.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  268.  
  269.     /*
  270.      *    return success
  271.      */
  272.     return;
  273. }
  274.